<div class="form wide grid-view">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'packing-list-packages-cargo-form',
	'enableAjaxValidation'=>false,
)); ?>
	
	<table class="items">
		<thead>
		<tr>
			<td colspan="4">
				<a href="#" id="add">Add</a>
			</td>
		</tr>
		<tr>
			<th><?php echo $form->Label($model['package_cargo'][0],'package_id');?></th>
			<th><?php echo $form->Label($model['dimension'][0],'qty');?></th>
			<th><?php echo $form->Label($model['dimension'][0],'wt');?></th>
			<th><?php echo $form->Label($model['dimension'][0],'m3');?></th>
		</tr>
		</thead>
		<tbody>
		<?php foreach($model['package_cargo'] as $i=>$item):?>
		<tr>
			<td><?php echo $form->DropDownList($item,"[$i]package_id",CHtml::listData($model['cargo']->packing_list->packages,'id','marking'),array()); ?></td>
			<td>
				<?php echo $form->TextField($model['dimension'][$i],"[$i]qty",array("maxlength"=>11,"size"=>6,'placeholder'=>'Quality')); ?>
				<?php echo $form->DropDownList($model['dimension'][$i],"[$i]qty_type",$model['dimension'][$i]->qtytype,array("style"=>"width:50px;"));?>
			</td>
			<td>
				<?php echo $form->TextField($model['dimension'][$i],"[$i]wt",array("size"=>6,"maxlength"=>11,'placeholder'=>'Weight')); ?>
        		<?php echo $form->DropDownList($model['dimension'][$i], "[$i]wt_type", $model['dimension'][$i]->wttype,array("style"=>"width:50px;"));?>  
			</td>
			<td>
				<?php echo $form->TextField($model['dimension'][$i],"[$i]m3",array("size"=>6,"maxlength"=>15, "placeholder"=>"Length")); ?>
			</td>
		</tr>
		<?php endforeach;?>
		</tbody>
	</table>
	<div class="row buttons">
		<?php 
        	$this->widget('zii.widgets.jui.CJuiButton',array(
        		'name'=>'submit',
        		'caption'=>($model['package_cargo'][0]->isNewRecord)?'Save':'Update',
        		'value'=>"submit",
        	)); 
        ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->
<?php
$packageUrl = CHtml::normalizeUrl(array('packing_list_packages/view'));
$cs = Yii::app()->getClientScript();
$script = <<<EOD
	$.packing_list_packages_cargo = {
		afterSubmit:function(data){window.location = "$packageUrl?id="+data.id;}
	};
	$('#packing-list-packages-cargo-form [type=submit]').click(function(){
		var form = $.extend($.simplelogform,$.packing_list_packages_cargo);
		form.Submit($('#packing-list-packages-cargo-form'));
		return false;
	});
	$('a#add').click(function(){
		var table = $(this).parents('table');
		AddNewTableRow(table);
		return false;
	});
EOD;
$cs->registerScript('packing_list_packages_cargo#form',$script);
?>